package com.asialjim.wechat.apiservice.constant;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.time.Duration;
import java.util.concurrent.TimeUnit;

/**
 * <h1><em>ASIAL JIM JAVA DOC</em></h1><hr/>
 * <h2>ENUM DESCRIPTION <i>[ NAME: WeChatCache ]</i></h2><strong>
 * <p> we chat cache
 * </strong><p><p><em>Copyright &copy; Asial Jim Co., LTD</em><hr/>
 *
 * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
 * @version 1.0.0
 * @since 2021/3/17   &nbsp;&nbsp; JDK 8
 */
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public enum WeChatCache {
    WE_CHAT_ACCESS_TOKEN(WeChatCacheName.WECHAT_ACCESS_TOKEN,90L,TimeUnit.MINUTES),
    WE_CHAT_JS_ACCESS_TOKEN(WeChatCacheName.WECHAT_JS_ACCESS_TOKEN,7L,TimeUnit.DAYS),
    WE_CHAT_ACCOUNT_ALL(WeChatCacheName.WECHAT_ACCOUNT_ALL,30L,TimeUnit.DAYS),
    WE_CHAT_ACCOUNT(WeChatCacheName.WECHAT_ACCOUNT,30L,TimeUnit.DAYS),
    WE_CHAT_SUBJECT(WeChatCacheName.WECHAT_SUBJECT,30L,TimeUnit.DAYS),
    WE_CHAT_MESSAGE(WeChatCacheName.WECHAT_MESSAGE,20L,TimeUnit.MINUTES),
    ;

    private final String cacheName;
    private final Long expiresIn;
    private final TimeUnit timeUnit;


    public Duration duration(){
        switch (timeUnit){
            case  SECONDS:
                return Duration.ofMillis(expiresIn);
            case MINUTES:
                return Duration.ofMinutes(expiresIn);
            case HOURS:
                return Duration.ofHours(expiresIn);
            case DAYS:
                return Duration.ofDays(expiresIn);
            default:
                return Duration.ofMillis(expiresIn);
        }
    }
}
